﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StyleMVVM.Messenger
{
	public static class IDispatchedMessengerExtensions
	{
		/// <summary>
		/// Registers a new Action(T) handler for receiving messages of type T
		/// </summary>
		/// <typeparam name="T"></typeparam>
		/// <param name="messenger"></param>
		/// <param name="action"></param>
		/// <param name="background"></param>
		/// <param name="holdReference"></param>
		public static void Register<T>(this IDispatchedMessenger messenger,
		                               Action<T> action,
		                               bool background = false,
		                               bool holdReference = false)
		{
			messenger.Register((object)action, background, holdReference);
		}

		/// <summary>
		/// Unregister an Action(T) handler
		/// </summary>
		/// <typeparam name="T"></typeparam>
		/// <param name="messenger"></param>
		/// <param name="action"></param>
		public static void Unregister<T>(this IDispatchedMessenger messenger,
		                                 Action<T> action)
		{
			messenger.Unregister((object)action);
		}
	}
}